package com.lukebang.service.serviceImpl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;

import com.lukebang.constant.Const;
import com.lukebang.dao.MerchantsWalletRecordDAO;
import com.lukebang.pojo.Indent;
import com.lukebang.pojo.MeasureIndent;
import com.lukebang.pojo.Merchant;
import com.lukebang.pojo.MerchantsWalletRecord;
import com.lukebang.service.MerchantsWalletRecordService;
@Service("MerchantsWalletRecordService")
public class MerchantsWalletRecordServiceImpl implements MerchantsWalletRecordService{
	@Resource
	private MerchantsWalletRecordDAO merchantsWalletRecordDAO;
	@Override
	public Map<String, Object> selectWorkerWalletRecordByWorkerInfoAndTimeCondition(HttpSession session,String recordBeginTime,String recordEndTime,Integer indentId,Integer offset, Integer limit,
			String sort, String order) {
		//得到登陆的商户的信息
		Merchant merchant = (Merchant) session.getAttribute(Const.SESSION_USER);
		Map<String, Object> retsMap = new HashMap<String, Object>();
		retsMap.put("total", 0);
		Map<String,Object>queryMap=new HashMap<String,Object>();
		queryMap.put("offset", offset);
		queryMap.put("limit", limit);
		queryMap.put("sort", sort);
		queryMap.put("order", order);
		queryMap.put("merchantsId", merchant.getMerchantsId());
		queryMap.put("indentId", indentId);
		queryMap.put("recordBeginTime", recordBeginTime);
		//如果查询的结束时间为空，则默认为系统当前时间
		if(recordEndTime==null | "".equals(recordEndTime)) {
			Date nowDate=new Date();
			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");			
			recordEndTime=sdf.format(nowDate);
		}
		queryMap.put("recordEndTime", recordEndTime);
		List<MerchantsWalletRecord> beans=new ArrayList<MerchantsWalletRecord>();
		beans=merchantsWalletRecordDAO.selectMerchantWalletRecordsDetail(queryMap);
		retsMap.put("total", merchantsWalletRecordDAO.selectMerchantsWalletRecordCountByMerchant(queryMap));
		retsMap.put("rows", beans);
		return retsMap;
	}

}
